package tms.business.jabber;

import tms.business.notification.NotificationBroker;
import tms.business.notification.NotificationMethod;
import tms.business.notification.NotifyBy;
import tms.model.login.UserEntity;
import tms.model.profile.UserProfileEntity;
import tms.util.jabber.JabberManager;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.List;

@NotifyBy(NotificationMethod.JABBER)
@ApplicationScoped
public class JabberNotificationBroker implements NotificationBroker {
    @Inject
    JabberManager jabberManager;

    @Override
    public void notifyUsers(List<UserEntity> users) {
        for (UserEntity user : users) {
            UserProfileEntity profile = user.getProfile();
            if (profile.getJabberActive() && profile.getJabberNotify()) {
                jabberManager.sendMessage(profile.getJabberId(), profile.getJabberNotifyMessage());
            }
        }
    }
}
